<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-button icon="el-icon-arrow-left" type="text" @click="delRouter"
          >返回</el-button
        ><span>| 待{{this.$route.query.title}}记录</span>
      </el-col>
    </el-row>
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="复查结果"  v-if="this.$route.query.title =='复查'">
        <el-radio v-model="form.operatorStatus" label="3">合格</el-radio>
        <el-radio v-model="form.operatorStatus" label="2">不合格</el-radio>
      </el-form-item>
      <el-form-item label="整改结果" v-else>
        <el-radio v-model="form.operatorStatus" label="1">已整改</el-radio>
        <el-radio v-model="form.operatorStatus" label="4">未整改</el-radio>
      </el-form-item>
      <el-form-item label="分包单位">
        <el-select
          v-model="form.subpackageUnitIds"
          placeholder="请选择分包单位"
          style="width: 400px"
        >
          <el-option
            v-for="(item, index) in formList.getSubUnitsList"
            :key="index"
            :value="item.id"
            :label="item.enterpriseName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="复查说明" v-if="this.$route.query.title =='复查'">
        <el-input
          type="textarea"
          :rows="4"
          v-model="form.operatorExplain"
          style="width: 400px"
          placeholder="请输入复查说明"
        ></el-input>
      </el-form-item>
      <el-form-item label="整改回复" v-else>
        <el-input
          type="textarea"
          :rows="4"
          v-model="form.operatorExplain"
          style="width: 400px"
          placeholder="请输入复查说明"
        ></el-input>
      </el-form-item>
      <el-form-item label="现场照片">
        <ImageUpload v-model="form.fileName"></ImageUpload>
      </el-form-item>
      <el-form-item label="需要罚款">
        <el-radio v-model="form.isFine" label="0">不罚款</el-radio>
        <el-radio v-model="form.isFine" label="1">罚款</el-radio>
      </el-form-item>
      <div v-if="form.isFine == '1'">
        <el-form-item label="罚款金额">
          <el-input-number
            v-model="form.fineMoney"
            :min="0"
            :max="999999999999999999"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="罚款说明">
          <el-input
            type="textarea"
            :rows="4"
            v-model="form.fineExplain"
            style="width: 400px"
            placeholder="请输入罚款说明"
          ></el-input>
        </el-form-item>
      </div>
      <el-form-item style="margin-left: 160px">
        <el-button type="primary" @click="submitData">保存</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { getSubUnits,reviewSubmit } from "@/api/biz/ledger/ledger";
export default {
  data() {
    return {
      form: {
        recordId: this.$route.query.id,
        projectId: this.$route.query.projectId,
        operatorType:null,
      },
      //下拉数据
      formList: {
        revisePeopleList: [], //整改人
        dutyAreaList: [],
        checkTypeList: [],
        getSubUnitsList: [],
      },
      queryParams: {
        projectId: this.$store.state.app.selectData,
        hiddenTrouble: "0",
      },
    };
  },

  methods: {
    //关闭
    delRouter() {
      this.$router.push({ name: "Ledger" });
      this.$store.state.tagsView.visitedViews =
        this.$store.state.tagsView.visitedViews.filter(
          (item) => item.name !== "ReviewLedger"
        );
    },
    getList() {
      getSubUnits().then((response) => {
        this.formList.getSubUnitsList = response.rows;
        if (this.$route.query.title !='复查') {
          this.form.operatorStatus = '1'
        }
      });
    },
    //保存
    submitData() {
      if (this.$route.query.title =='整改') {
        this.form.operatorType = '2'
      }else{
        this.form.operatorType = '1'
      }
      reviewSubmit(this.form).then((data) => {
        if (data.code == 200) {
          this.$message({
            message: "提交成功！",
            type: "success",
          });
          this.$router.push({ name: "Ledger" });
          this.$store.state.tagsView.visitedViews =
            this.$store.state.tagsView.visitedViews.filter(
              (item) => item.name !== "ReviewLedger"
            );
        }
      });
    },
  },

  components: {},

  computed: {
    ...mapState(["app"]),
  },

  created() {
    this.getList();
  },
  watch: {
    $route: {
      handler(newVal, oldVal) {
        if (oldVal.name == "ReviewLedger") {
          this.$store.state.tagsView.visitedViews =
            this.$store.state.tagsView.visitedViews.filter(
              (item) => item.name !== "ReviewLedger"
            );
        }
      },
      deep: true,
    },
    app: {
      handler(newVal, oldVal) {
        this.form.projectId = newVal.selectData;
        this.getList();
      },
      deep: true,
    },
  },
};
</script>
<style scoped>
.dialog-box {
  height: 500px;
  border: 1px solid #000;
  display: flex;
}
</style>
